﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
//
//class Solution {
//public:
//    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
//        int left = 0, right = 0;
//        int ret=0;
//        for (int i = 0; i < timeSeries.size(); ++i)
//        {
//            if ((i + 1 < timeSeries.size()) && (timeSeries[i] + duration - 1) >= timeSeries[i + 1])
//            {
//                ret += duration;
//            }
//            else if ((i + 1 < timeSeries.size()) && (timeSeries[i] + duration - 1) < timeSeries[i + 1])
//            {
//                ret += timeSeries[i + 1] - timeSeries[i] + 1;
//            }
//        }
//        return ret;
//    }
//};

////提莫攻击（easy）模拟，根据题目要求解答
//
//class Solution {
//public:
//    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
//        int n = timeSeries.size() - 1;
//        int ret = 0;
//        for (int i = 0; i < timeSeries.size(); ++i)
//        {
//            if ((i + 1 < timeSeries.size()) && (timeSeries[i] + duration) <= timeSeries[i + 1])
//            {
//                ret += duration;
//            }
//            else if ((i + 1 < timeSeries.size()) && (timeSeries[i] + duration) > timeSeries[i + 1])
//            {
//                ret += timeSeries[i + 1] - timeSeries[i];
//            }
//        }
//
//        return ret + duration;
//    }
//};

class Solution
{
public:
    string convert(string s, int numRows)
    {
        // 处理边界情况 
        if (numRows == 1) return s;

        string ret;
        int d = 2 * numRows - 2, n = s.size();

        // 1. 先处理第⼀⾏ 
        for (int i = 0; i < n; i += d)
            ret += s[i];

        // 2. 处理中间⾏ 
        for (int k = 1; k < numRows - 1; k++) // 枚举每⼀⾏ 
        {
            for (int i = k, j = d - k; i < n || j < n; i += d, j += d)
            {
                if (i < n) ret += s[i];
                if (j < n) ret += s[j];
            }
        }

        // 3. 处理最后⼀⾏ 
        for (int i = numRows - 1; i < n; i += d)
            ret += s[i];
        return ret;
    }
};



int main()
{
    vector<int> v = { 1,4 };
    Solution s;
   /* s.findPoisonedDuration(v, 2);*/
    return 0;
}